import 'dart:async';

import 'package:base_plugin/base_plugin.dart';

mixin ValidateCodeMixin<T> on BaseProvider<T> {
  Timer timer;

  //默认的过期时间
  int defaultOTPExpireTime = 90;

  //当前过期时间
  int currentOTPExpireTimer = 0;
  bool hasValidateError = false;

  void resetTimer() {
    timer?.cancel();
    currentOTPExpireTimer = defaultOTPExpireTime;
    timer = Timer.periodic(Duration(seconds: 1), (timer) {
      if (currentOTPExpireTimer > 0) {
        currentOTPExpireTimer--;
        update();
      } else {
        timer?.cancel();
      }
    });
  }

  @override
  void dispose() {
    timer?.cancel();
    super.dispose();
  }
}
